﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ScoreMS.Views
{
    /// <summary>
    /// LoginPage.xaml 的交互逻辑
    /// </summary>
    public partial class LoginPage : Page
    {
        public LoginPage()
        {
            InitializeComponent();

            this.KeyDown += new KeyEventHandler(Login_KeyDown);
        }

        /// <summary>
        /// 回车输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void Login_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                btnLogin_Click(sender, e);
            }
        }

        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            if (txtTeacher_id.Text.Trim() == "")
            {
                MessageBox.Show("请输入工资号！", "提示");
                return;
            }
            string teacher_id = txtTeacher_id.Text.Trim();
            if (BLL.TeatherBS.IsExists(teacher_id))     //是第一次连接数据库！耗时！ToDo：加个Loading
            {
                App.teacher_id = teacher_id;
                App.is_Logined = true;
                App.MainViewModel.Teacher = BLL.TeatherBS.GetTeacherInfo(teacher_id);
                
                NavigationService.Navigate(new Uri("Views/Default.xaml", UriKind.Relative));
            }
            else
            {
                MessageBox.Show("系统中不存在此教师！请联系管理员添加！", "提示");
            }
        }
    }
}
